/**
* @description: 926. 将字符串翻转到单调递增
* @author hewei
* @date 2022/9/20 15:31
* @version 1.0
*/

public class MinFlipsMonoIncr {

    public int minFlipsMonoIncr(String s) {
        int one = s.charAt(0) == '0' ? 1 : 0;
        int zero = one == 0 ? 1 : 0;
        for (int i = 1; i < s.length(); i++) {
            char c = s.charAt(i);
            int temp = Math.min(zero, one);
            if (c == '0') {
                one = temp + 1;
            } else {
                one = temp;
                zero++;
            }
        }
        return Math.min(zero, one);
    }
}
